import env from 'src/config';
import CryptoJS from 'crypto-js';
import api from 'src/plugins/http/api';
import { showLoadingToast, closeToast, showToast } from 'vant';



const { appkey, path } = env;

export const link = (href, reload = false) => {
    window.location.href = `${path}#${href}`;
    if (reload) { window.location.reload(); }
};

export const utilConfig = {
    'duration': 2000
};

// 参数加密
export function aesEncrypt(data, key = appkey) {
    return CryptoJS.AES.encrypt(JSON.stringify(data), key).toString();
}
// 参数解密
export function aesDecrypt(text, key = appkey) {
    const bytes = CryptoJS.AES.decrypt(text, key);
    try {
        return JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
    } catch (e) {
        return {};
    }
}

export function closeAll() {
    closeToast()
}

export function msgFn(options = {}) {
    return showToast({
        message: '',
        wordBreak: 'break-all',
        ...options
    });
}

export function showNotification(options = {}) {

}

export function confirmFn(message, yesFn, noFn) {

}
export function hideLoading(options = {}) {
    closeToast()
}
export function showLoading(options = {}) {
    return showLoadingToast({
        message: '加载中...',
        forbidClick: true,
        duration: 0,
        ...options
    });
}
